package net.dgg.zz.common.utils.excel;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;


/**
 * <p>@Title 获取类的字段  </p>
 * <p>@author HDC</p>
 * <p>@date 2018/5/7 10:57 </p>
 * <p>@Copyright © dgg group.All Rights Reserved. 版权信息</p>
 */

public class ReflectUtils {
    public static Field[] getClassFields(Class c){
        return c.getDeclaredFields();
    }

    public static Field[] getClassAndSuperClassFields(Class c){
        List<List<Field>> queue = new ArrayList<>();
        while (c != null && !c.getName().toLowerCase().equals("java.lang.object")){
            List<Field> node = new ArrayList<>();
            node.addAll(Arrays.asList(c.getDeclaredFields()));
            queue.add(node);
            c = c.getSuperclass();
        }
        List<Field> fields = new ArrayList<>();
        Collections.reverse(queue);
        queue.forEach(n -> fields.addAll(n));
        return fields.toArray(new Field[fields.size()]);
    }
}
